<template>
  <div class="home">
    <MainLayout :active-index="activeIndex" :header-menu-data="headerMenu"/>
  </div>
</template>

<script>
import {$SysMenuApi} from "@/network/menu/SysMenuApi";
import MainLayout from "@/components/layout/MainLayout";

export default {
  name: 'HomeView',
  components: {
    MainLayout

  },
  data() {
    return {
      headerMenu: [],
      activeIndex: "",
    }
  },

  methods: {
    handleBtnClick() {

    },

    async loadTopMenus() {
      const res = await $SysMenuApi.getTopMenus();
      this.headerMenu = res.data;
      window.sessionStorage.setItem("topMenus", JSON.stringify(res.data));
      let activePath = window.sessionStorage.getItem("activePath");
      if (activePath) {
        await this.$router.push({
          path: activePath
        })
        this.activeIndex = "/" + activePath.split("/")[1];
      } else {
        let item = this.headerMenu.filter(r => r.defaultActive === "1");
        if (item) {
          await this.$router.push({
            path: item[0].path
          })
        }
      }
    }

  },

  mounted() {

  },

  created() {
    this.loadTopMenus();
    this.$store.dispatch("NavBar/getMunu");
  }
}
</script>

<style scoped>
  .home {
    height: 100%;
  }
</style>
